package com.ckf.serene.controller;

import com.ckf.serene.domain.AliPayParam;
import com.ckf.serene.domain.AliPayRefundParam;
import com.ckf.serene.service.AliPayService;
import com.ckf.serene.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 支付宝api
 * <p>
 * 传参规范按照官方文档
 *
 * @author serence
 * @date 2021/11/6 23:39
 */
@Slf4j
@RestController
@RequestMapping("/aliPayPay/")
public class AliPayController {

    @Autowired
    private AliPayService aliPayService;


    /**
     * 支付宝APP支付
     *
     * @param aliPayParam 支付宝参数类
     * @return
     */
    @PostMapping("aliPayAPPToPay")
    public AjaxResult aliPayAPPToPay(@RequestBody AliPayParam aliPayParam) {
        return AjaxResult.success(aliPayService.aliPayAPPToPay(aliPayParam));
    }


    /**
     * 支付宝退款
     *
     * @param payRefund 支付宝退款参数类
     * @return
     */
    @PostMapping("aliPayRefund")
    public AjaxResult aliPayRefund(@RequestBody AliPayRefundParam payRefund) {
        return AjaxResult.success(aliPayService.aliPayRefund(payRefund));
    }


    /**
     * 支付宝APP支付
     *
     * @param request 回调内容
     * @return
     */
    @PostMapping("aliPayNotify")
    public AjaxResult aliPayNotify(HttpServletRequest request) {
        return AjaxResult.success(aliPayService.aliPayNotify(request));
    }


}
